class Solution:
    def myAtoi(self, s: str) -> int:
        n = ""
        for i in s:
            if i == " " and n == "":
                continue
            elif i in "+-" and n == "":
                n += i
            elif i in "1234567890":
                n += i
            else:
                break
        if n == "+" or n == "-" or n == "":
            return 0
        else:
            n = int(n)
            if n <= -2**31:
                return -2**31
            elif n >= 2**31 - 1:
                return 2**31-1
            else:
                return n

if __name__ == '__main__':
    s = Solution()
    print(s.myAtoi("42"))
    print(s.myAtoi(" -042"))
    print(s.myAtoi("1337c0d3"))
    print(s.myAtoi("0-1"))
    print(s.myAtoi("words and 987"))
    print(s.myAtoi("-91283472332"))
    print(s.myAtoi("-"))
    print(s.myAtoi("3.14159"))
